using UnityEditor;
using UnityEngine;

namespace Gameplay.PVE.Editor
{
    [CustomEditor(typeof(BattleUnitLog))]
    public class BattleUnitLogEditor : UnityEditor.Editor
    {
        private BattleUnitLog logger { get {  return target  as BattleUnitLog; } }
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Clear"))
            {
                logger.Clear();
            }

            foreach (var item in logger.staticLogDic)
            {
                GUILayout.BeginHorizontal();
                GUILayout.TextField(item.Key + " " + item.Value.content);
                string btn = item.Value.isShowDetail ? "-" : "+";
                if (GUILayout.Button(btn))
                {
                    item.Value.isShowDetail = !item.Value.isShowDetail;
                }
                GUILayout.EndHorizontal();
                if (item.Value.isShowDetail)
                {
                    GUILayout.TextField(item.Value.stackTrace);
                }
            }
            
            for (int i = 0; i < logger.logList.Count; i++)
            {
                GUILayout.BeginHorizontal();
                GUILayout.TextField(logger.logList[i].content);
                string btn = logger.logList[i].isShowDetail ? "-" : "+";
                if (GUILayout.Button(btn))
                {
                    logger.logList[i].isShowDetail = !logger.logList[i].isShowDetail;
                }
                GUILayout.EndHorizontal();
                if (logger.logList[i].isShowDetail)
                {
                    GUILayout.TextField(logger.logList[i].stackTrace);
                }
            }
            //base.OnInspectorGUI();
        }
    }
}